/**
* @description: 404. 左叶子之和
* @author hewei
* @date 2022/8/1 15:36
* @version 1.0
*/

public class SumOfLeftLeaves {

    public int sumOfLeftLeaves(TreeNode root) {
        return process(root, false);
    }

    public int process(TreeNode node, boolean flag) {
        if (node == null) return 0;
        int l = process(node.left, true);
        int r = process(node.right, false);
        return flag && node.left == null && node.right == null ? node.val : l + r;
    }
}
